home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws24.zip / ENC.C < prev    next >
Text File  |  1988-05-18  |  1KB  |  60 lines

  1. #include "c:\s87\misc\nandef.h"
  2. #include "c:\s87\misc\extend.h"
  3.  
  4. /*
  5.   Function: ENCRYPT()
  6.     Syntax: ENCRYPT( <expC1>, <expC2>, BUFFER )
  7.    Purpose: To encrypt <expC1> using <expC2> as the key and
  8.             storing the result in BUFFER.
  9.     Author: Bao Hoang
  10.       Date: 03/02/88
  11.       Time: 01:32:46
  12. Documented: Not really.
  13. */
  14.  
  15. CLIPPER encrypt()
  16. {
  17. char *string,            /* string to encrypt */
  18.      *key,               /* key to use for encryption */
  19.      *res,               /* string to put result in */
  20.      *tmp,               /* temporary key pointer */
  21.      *res_ptr;           /* result temporary pointer */
  22.  
  23. int  s_len,              /* length of string to encrypt */
  24.      k_len,              /* length of key */
  25.      tk_len;             /* temporray key length counter */
  26.  
  27. /*
  28. Step 1: Get the parameters!
  29.         C me interface?  (chuckle, chuckle...)
  30. */
  31.  
  32. string = _parc(1);
  33. s_len  = _parclen(1);
  34. key    = _parc(2);
  35. k_len  = _parclen(2);
  36. res    = _parc(3);
  37.  
  38. /*
  39. Step 2: Go encrypt the thang!
  40. */
  41.  
  42. res_ptr = res;
  43. tk_len = k_len;
  44.  
  45. for (tmp = key; s_len-- > 0; *res_ptr++ = *string++ ^ *tmp++)
  46.    if (tk_len-- == 0)
  47.       {
  48.       tmp = key;
  49.       tk_len = k_len;
  50.       }
  51. /*
  52. Step 3: Let's go home!
  53. */
  54.  
  55. _ret();
  56. }
  57.  
  58.  
  59.  
  60.